<#include "/basicdata/common/scripts.html">
<#include "/basicdata/common/scripts_add2.html">
<body>
<style>
    .bootstrap-select{
        width: 71%!important;
    }
</style>
<div class="fh-model" style="height:400px;">
    <div class="oper-search">
        <form class="form-inline" id="searchForm">
            <div class="form-group">
                <label  class="control-label-query text-justify" >岗位名称 <span class="span-justify"></span></label>
                <input id="postName" name="postName" type="text" class="form-control" autocomplete="off"/>
            </div>
            <div class="form-group">
                <label  class="control-label-query text-justify" >岗位编码 <span class="span-justify"></span></label>
                <input id="postCode" name="postCode" type="text" class="form-control" autocomplete="off"/>
            </div>
            <div class="form-group">
                <span class="btn glyphicon glyphicon-search btn-sm" onclick="searchPostGroupBtn()">查询</span>
            </div>
        </form>
    </div>
    <table id="postGroupTable" class="eamtable">
    </table>

</div>
<div class="div-model-btn">
    <div class="model-btn" onclick="sub()">确定</div>
</div>
</body>
<script>
    //全局变量，复选框选中项
    var chk_value = [];

    $(function () {
        //二次添加带出已选项
        var idz = "";
        if (idz != "") {
            chk_value = idz.split(",");
        }
    });
    var postGroupTable = $("#postGroupTable");
    $(function() {
        sys.useSimpleRetrieveData();
        var staticPrefix = "${static}";
        var config = sys.DynamicDatabeConfig(staticPrefix,getSearchUrl(),[
            {   data:null,
                title:"" ,
                render:function(data){
                    return  '<div class="pretty success" style="margin: 0;">'
                        +'<input type="checkbox" data-id="'+data.id+'" onclick="addAndRemove(this)"  class="item-checkbox" /> '
                        +'  <label><i class="mdi mdi-check"></i></label>'
                        +'</div>';
                },width:20
            },
            {data: "postName", title: "岗位名称"},
            {data: "postCode", title: "岗位编码"},
        ],true, {ordering:true});
        config.bSort=false;
        config.aLengthMenu = [10,25,50,100];
        config.scrollX = true;
        config.autoWidth=true;
        config.scrollY = '65%';
        postGroupTable.dataTable(config);
        postGroupTable.DataTable().on('draw', function() {
            sys.initMenuPower();
            checkGroup.autoSetSelect();
        });
    })

    function getSearchParam() {
        var postCode = $("#postCode").val().trim();
        var postName = $("#postName").val().trim();
        var param = 'postCode='+postCode+'&postName='+postName+"&companyCode=${companyCode!}&postGroupIdNotIn=${postGroupIdNotIn!}";
        return param;
    }

    function getSearchUrl(){
        var url = '${ctx}/user/ajaxPostGroupPageInfo?' + getSearchParam();
        url = encodeURI(url);
        return url;
    }

    function searchPostGroupBtn() {
        postGroupTable.DataTable().ajax.url(getSearchUrl()).load(null, false);
    }

    var checkGroup = new iUtils.CheckGroup({
        table:postGroupTable,
        callback:function(table,ele,arr){
            var data = table.fnGetData($(ele).parents("tr")[0]);
            var id = data.id;
            data.id = "";
            arr[id] = data;
        }
    });

    function sub(){
        debugger;
        //var arr = checkGroup.getAllCheckedIds();
        var rows = [];
        var nTrs = postGroupTable.fnGetNodes();
        $("[type='checkbox']:checked").each(function () {
            var data = postGroupTable.fnGetData($(this).parents("tr")[0]);
            rows.push(data);
        });
        parent.addSubUserPostGroup(rows);
        sys.frameDialogClose();
    }
    function appNameChange() {
        postGroupTable.DataTable().ajax.url(getSearchUrl()).load(null, false);
    }
</script>